package com.gugugu.web.rpc.factory;

import com.gugugu.web.rpc.util.SpringUtil;
import com.guguguweb.rpc.net.client.proxy.GuRpcClientProxy;
import org.springframework.beans.factory.FactoryBean;

/**
 * TODO
 *
 * @author chenke
 * @version 1.0
 * @date 2021-12-22 14:51
 */
public class GuRpcClientMapperFactoryBean<T> implements FactoryBean<T> {

    private Class<T> guInterface;


    private GuRpcClientProxy guRpcClientProxy;

    public GuRpcClientMapperFactoryBean() {
    }

    public GuRpcClientMapperFactoryBean(Class<T> guInterface) {
        this.guInterface = guInterface;
        guRpcClientProxy = SpringUtil.getBean("defaultGuRpcClientProxy", GuRpcClientProxy.class);

    }

    /**
     * bean实例化对象,指向代理类即可
     */
    @Override
    public T getObject() throws Exception {
        T proxy = guRpcClientProxy.getProxy(guInterface);
        return proxy;
    }

    /**
     * bean对象类型
     */
    @Override
    public Class<T> getObjectType() {
        return this.guInterface;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}

